const path = require('path');
const fs = require('fs');
const { getIndexURLAndPublicPath, getPluginPath } = require('./utils');
const { log } = console;

const appDirectory = process.env.WECODE_APP_PATH;
const runtimePath = process.env.RUNTIME_PATH;

const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
const resolveRuntime = relativePath => path.resolve(runtimePath, relativePath);

// 请勿改动
const distPath = 'build/apps/local/0/';

let eslintNodeModules = process.env.ESLINT === 'true' ? resolveRuntime('./node_modules') : null;


const { baseURL, webpackPublicPath } = getIndexURLAndPublicPath(appDirectory);

if (eslintNodeModules) {
  eslintNodeModules = process.env.WECODE_ESLINT_PATH;
  if (!fs.existsSync(eslintNodeModules)) {
    log('WecodeEslintConfigPath is not exists.');
    eslintNodeModules = null;
  }
}
log('------ get eslint', eslintNodeModules)
module.exports = {
  appPath: appDirectory,
  vendorsDll: resolveApp('./vendor'),
  commonPath: resolveApp('node_modules/@wecode/wlk-jsapi/lib/common'),
  toCommonPath: resolveApp(distPath + 'common'),
  pluginPath: getPluginPath(appDirectory),
  buildPath: resolveApp(distPath),
  appHtml: resolveApp('./src/index.html'),
  appEntry: resolveApp('src/main.js'),
  eslintNodeModules,
  baseURL,
  publicPath: resolveApp('./public'),
  webpackPublicPath
}
